# utf-8

obeservers = []

# [(who, how), (who, how)]

"""
{"who", "how"}
"""

def obeserve_batch_notify_func():
    """
    有新闻发生，通知给所有的订阅者
    """

    for ob in obeservers:
        print("will notify who:%s"%ob[0])
        ob[1]()
    pass

def add_subscribe(who, how):
    """
    向报社定报纸
    """
    print("add sub, who:%s, how:%s"%(who, how))

    obeservers.append((who, how))

    pass

def rmv_subscribe(who):
    """
    向报社取消订报纸
    """
    print("add sub, who:%s"%who)
    for ob in obeservers:
        if ob[0] == who:
            obeservers.remove((who, ob[1]))
            return


sub_1 = "sub_1"
def notify_sub_1():
    print("notify me, my name's sub_1")


sub_2 = "sub_2"
def notify_sub_2():
    print("notify me, my name's sub_2")
    


if __name__ == '__main__':
    add_subscribe(sub_1, notify_sub_1)
    add_subscribe(sub_2, notify_sub_2)

    # when news happend
    obeserve_batch_notify_func()


